package com.sunway.netty.secondexample;

import java.util.UUID;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class SecondServerHandler extends SimpleChannelInboundHandler<String>{

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
		//收到客户端的发送数据
		System.out.println(ctx.channel().remoteAddress() + ": " + msg);
		ctx.channel().writeAndFlush("from server: " + UUID.randomUUID());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		//处理发生异常时断开
		cause.printStackTrace();
		ctx.close();
	}

	
}
